﻿using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;

namespace ComfirmSubscriber
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            var connection = factory.CreateConnection();
            var channel = connection.CreateModel();
            channel.ConfirmSelect();
            channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
            var consumer = new EventingBasicConsumer(channel);
            consumer.Received += (sender, ea) =>
            {
                Console.WriteLine($"{Encoding.UTF8.GetString(ea.Body.ToArray())}");
                Thread.Sleep(20000);
                ((EventingBasicConsumer)sender).Model.BasicNack(ea.DeliveryTag, multiple: false, requeue: false);
            };
            channel.BasicConsume(queue: "hello", autoAck: false, consumer: consumer);

            Console.ReadLine();
        }
    }
}